/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package dao;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;
import javax.faces.model.SelectItem;

/**
 *
 * @author amkreuz
 */
public class HouseListDAO
{
 
    public static Connection DBConn;
    
    public static void init() throws SQLException{
         try {
            Class.forName("org.apache.derby.jdbc.ClientDriver");
        } catch (ClassNotFoundException e) {
            System.err.println(e.getMessage());
            System.exit(0);
        }
        DBConn = DriverManager.getConnection("jdbc:derby://localhost:1527/ChoreBoard");
    }
    
    public static void terminate() throws SQLException{
        DBConn.close();
    }
    
    public static List<SelectItem> getHouseList() throws SQLException
    {
        List<SelectItem> list = new ArrayList<SelectItem>();
        Statement stmt = DBConn.createStatement();
        ResultSet rs = stmt.executeQuery("select housename from household");
        while (rs.next()) 
        {
            String house = rs.getString("housename");
            list.add(new SelectItem(house,house));
        }
        return list;
    }
}
